<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试预约报名信息</title>
    <script type="text/javascript" src="/test/js/jquery/jquery-2.2.4.js"></script>
    <script type="text/javascript">
        //        导出excel对象构造 这里相当于提交一个表单
        (function(){
            function is(obj, type) {
                return Object.prototype.toString.call(obj) === '[object ' + type + ']';
            }
            function tojson(data){
                var desc_data={};
                if(!data){
                    return {};
                }
                if(is(data, 'String')){
                    var data_arr=data.split('&');
                    $.each(data_arr,function(i,value){
                        var key_value_data=value.split('=');//获取键值对的data
                        desc_data[key_value_data[0]]=key_value_data[1];
                    });
                    return desc_data;
                }
                return data;
            }
            window.ExportExcel={
                submitToExport:function(btn_selector,url,data,timeout){
                    var _timeout=timeout || 10000;
                    var data=tojson(data);
                    var $form=$('<form action="'+url+'" method="POST" ></form>');
                    $.each(data,function(key,value){
                        var $input = null;
                        if(is(value,'Array')){
                            var input = '';
                            for(var i=0;i<value.length;i++){
                                input += '<input type="hidden" name="'+key+'['+i+']" value="'+value+'">';
                            }
                            $input=$(input);
                        }else{
                            $input=$('<input type="hidden" name="'+key+'" value="'+value+'">');
                        }

                        $form.append($input);
                    });
                    $submit=$('<input type="submit" style="display:none">');
                    $form.append($submit);
                    $(btn_selector).parent().append($form);
                    //提交
                    $submit.click();
                    setTimeout(function(){
                        $form.remove();
                    },_timeout)
                }
            };
        })();

    </script>
    <script type="text/javascript">
        $(function () {
            $("#A").click(function (e) {
                e.preventDefault();
                var url = "/admin/course/save";
                var name = $("#Aname").val();
                $.post(url, {name: name}, function (result) {
                    alert(JSON.stringify(result));
                })
            });
            $("#B").click(function (e) {
                e.preventDefault();
                var url = "/course/list";
                $.post(url, {}, function (result) {
                    alert(JSON.stringify(result));
                })
            });
            $("#C").click(function (e) {
                e.preventDefault();
                var url = "/admin/course/delete";
                var id = $("#Cid").val();
                $.post(url, {id: id}, function (result) {
                    alert(JSON.stringify(result));
                })
            });
            $("#D").click(function (e) {
                e.preventDefault();
                var url = "/reservation/save";
                var reservationName = $("#DreservationName").val();
                var reservationMobile = $("#DreservationMobile").val();
                var courseId = $("#DcourseId").val();
                $.post(url, {
                    reservationName: reservationName,
                    reservationMobile: reservationMobile,
                    courseId: courseId
                }, function (result) {
                    alert(JSON.stringify(result));
                })
            });
            $("#E").click(function (e) {
                e.preventDefault();
                var url = "/admin/reservation/page";
                var reservationName = $("#EreservationName").val();
                var reservationMobile = $("#EreservationMobile").val();
                var courseId = $("#EcourseId").val();
                var pageSize = $("#EpageSize").val();
                var pageNo = $("#EpageNo").val();
                $.post(url, {
                    reservationName: reservationName,
                    reservationMobile: reservationMobile,
                    courseId: courseId,
                    pageSize: pageSize,
                    pageNo: pageNo
                }, function (result) {
                    alert(JSON.stringify(result));
                })
            });
            $("#F").click(function (e) {
                e.preventDefault();
                var url = "/admin/reservation/save";
                var id = $("#Fid").val();
                var reservationName = $("#FreservationName").val();
                var reservationMobile = $("#FreservationMobile").val();
                var courseId = $("#FcourseId").val();
                $.post(url, {
                    id:id,
                    reservationName: reservationName,
                    reservationMobile: reservationMobile,
                    courseId: courseId
                }, function (result) {
                    alert(JSON.stringify(result));
                })
            });

            $("#G").click(function () {
//                e.preventDefault();
                $('#G').attr('disabled', 'disabled');
                var url = "/admin/reservation/export";
                var headers = $("#Gheaders").val();
                var contents = $("#Gcontents").val();
                ExportExcel.submitToExport('#G',url, {
                    headers: headers,
                    contents: contents
                });
                $("#G").removeAttr('disabled')
            });
        })



    </script>
</head>
<body>


<h3>添加课程</h3>
<input id="Aname" placeholder="课程名" type="text">
<button id="A">添加课程</button>
<hr>
<br><br>

<h3>获取课程</h3>
<button id="B">获取课程</button>
<hr>
<br><br>


<h3>删除课程</h3>
<input id="Cid" placeholder="课程id" type="text">
<button id="C">删除课程</button>
<hr>
<hr>
<br><br>

<h3>预约课程</h3>
<input id="DreservationName" placeholder="报名人姓名" type="text">
<input id="DreservationMobile" placeholder="报名人手机号" type="text">
<input id="DcourseId" placeholder="课程id" type="text">
<button id="D">预约课程</button>
<hr>
<br><br>

<h3>预约课程列表</h3>
<input id="EreservationName" placeholder="报名人姓名" type="text">
<input id="EreservationMobile" placeholder="报名人手机号" type="text">
<input id="EcourseId" placeholder="课程id" type="text">
<input id="EpageSize" type="text" placeholder="分页大小">
<input id="EpageNo" type="text" placeholder="页码">
<button id="E">预约课程列表</button>
<hr>
<br><br>


<h3>管理员编辑预约信息</h3>
<input id="Fid" placeholder="预约信息id" type="text">
<input id="FreservationName" placeholder="报名人姓名" type="text">
<input id="FreservationMobile" placeholder="报名人手机号" type="text">
<input id="FcourseId" placeholder="课程id" type="text">
<button id="F">管理员编辑预约信息</button>
<hr>
<br><br>


<h3>管预约信息导出</h3>
    <input id="Gheaders" placeholder="导出列的标题" type="text" value="预约人姓名,预约人手机号,课程">
    <input id="Gcontents" placeholder="导出列的属性名" type="text" value="reservationName,reservationMobile,reservationCourse">
    <button id="G">管预约信息导出</button>
<hr>
<br><br>

</body>
</html>